home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Risc World 3
/
Risc World 3.iso
/
SOFTWARE
/
ISSUE6
/
PD
/
PDF
/
Stl
/
h
/
memory
< prev
next >
Wrap
Text File
|
2003-02-14
|
3KB
|
91 lines
//--------------------------------------------------------------------------
//
// Copyright (c) 2002, Colin Granville
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or
// without modification, are permitted provided that the following
// conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// * The name Colin Granville may not be used to endorse or promote
// products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//
//--------------------------------------------------------------------------
#ifndef stl_memory_h
#define stl_memory_h
template<class T>
class auto_ptr
{
public:
auto_ptr(T* p=0): ptr(p) {}
~auto_ptr() {delete ptr;}
T& operator*() const {return *ptr;}
T* operator->() const {return ptr;}
T* get() const {return ptr;}
T* release() const
{
T* p=ptr;
((auto_ptr<T>*)this)->ptr=0;
return ptr;
}
auto_ptr(const auto_ptr<T>& a)
{
ptr=a.ptr;
((auto_ptr<T>&)a).ptr=0;
}
auto_ptr<T>& operator=(const auto_ptr<T>& rhs) const
{
if (this != &rhs)
{
if (ptr) delete ptr;
((auto_ptr<T>*)this)->ptr=rhs.ptr;
((auto_ptr<T>&)rhs).ptr=0;
}
return *((auto_ptr<T>*)this);
}
T* reset(T* a) const
{
if (a != ptr)
{
if (ptr) delete ptr;
((auto_ptr<T>*)this)->ptr=a;
}
return ptr;
}
private:
T* ptr;
};
#endif